package com.situ.mall.admin.controller;



import com.situ.mall.common.util.AliOSSUtil;
import com.situ.mall.common.util.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
@RequestMapping("/admin")
public class UploadController {
//    @Autowired
//    private RedisTemplate redisTemplate;

    @RequestMapping("/upload")
    public Result upload (MultipartFile file) {
        String uuid= UUID.randomUUID().toString().replace("-","");
        //a.png
        String fileName = file.getOriginalFilename();
        //.png
        String extension = fileName.substring(fileName.lastIndexOf("."));
        String newFileName = uuid + extension;
        //cvgfrewsxcf12345t.png
        
        //阿里云上传路径
        String url="";
        try {
            url= AliOSSUtil.uploadFile(newFileName,file.getInputStream());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        //把上传的图片放到Redis
//        redisTemplate.opsForSet().add(RedisConstants.UPLOAD_IMAGE,url);

        return Result.ok("上传成功！",url);
    }
}
